{extend name="store/storebase" /}

{block name="body"}
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<div class="main-title cf">
    <h2>登记网站信息</h2>
</div>
<!-- 表单 -->
<div class="tab-content">
    <!-- 表单 -->
    {php} $post_url || $post_url = U('edit?model='.$model['id']);{/php}
    <form id="form" action="{:$post_url}" method="post" class="form-horizontal form-center layui-form" lay-filter="xw-form">
        {include file="common@base/_form" /}
        <div class="form-item cf">
            {notempty name="data.id"}<input type="hidden" name="id" value="{$data.id|default=0}">{/notempty}
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定
            </button>
        </div>
    </form>

</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__PUBLIC__/admin/js/codemirror/codemirror.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/codemirror/xml.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/codemirror/javascript.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/codemirror/clike.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/codemirror/php.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__STATIC__/thinkbox/jquery.thinkbox.js?v={:SITE_VERSION}"></script>

<script type="text/javascript">
    function bindShow(radio_bind, selectors) {
        $(radio_bind).click(function () {
            $(selectors).toggleClass('hidden');
        })
    }

    //配置的动态
    bindShow('#has_config', '.has_config');
    bindShow('#has_adminlist', '.has_adminlist');

    $('#preview').click(function () {
        var preview_url = '{:U("preview")}';
        //console.log($('#form').serialize());
        $.post(preview_url, $('#form').serialize(), function (data) {
            $.thinkbox('<div id="preview_window" class="loading"><textarea></textarea></div>', {
                afterShow: function () {
                    var codemirror_option = {
                        lineNumbers: true,
                        matchBrackets: true,
                        mode: "application/x-httpd-php",
                        indentUnit: 4,
                        gutter: true,
                        fixedGutter: true,
                        indentWithTabs: true,
                        readOnly: true,
                        lineWrapping: true,
                        height: 500,
                        enterMode: "keep",
                        tabMode: "shift",
                        theme: "{:C('CODEMIRROR_THEME')}"
                    };
                    var preview_window = $("#preview_window").removeClass(".loading").find("textarea");
                    var editor = CodeMirror.fromTextArea(preview_window[0], codemirror_option);
                    editor.setValue(data);
                    $(window).resize();
                },

                title: '预览插件主文件',
                unload: true,
                actions: ['close'],
                drag: true
            });
        });
        return false;
    });

    $('.ajax-post_custom').click(function () {
        var target, query, form;
        var target_form = $(this).attr('target-form');
        var check_url = '{:U('
        checkForm
        ')}';
        $.ajax({
            type: "POST",
            url: check_url,
            dataType: 'json',
            async: false,
            data: $('#form').serialize(),
            success: function (data) {
                if (data.status) {
                    if (($(this).attr('type') == 'submit') || (target = $(this).attr('href')) || (target = $(this).attr('url'))) {
                        form = $('.' + target_form);
                        if (form.get(0).nodeName == 'FORM') {
                            target = form.get(0).action;
                            query = form.serialize();
                        } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                            query = form.serialize();
                        } else {
                            query = form.find('input,select,textarea').serialize();
                        }
                        $.post(target, query).success(function (data) {
                            if (data.status == 1) {
                                if (data.url) {
                                    updateAlert(data.info + ' 页面即将自动跳转~', 'alert-success');
                                } else {
                                    updateAlert(data.info + ' 页面即将自动刷新~');
                                }
                                setTimeout(function () {
                                    if (data.url) {
                                        location.href = data.url;
                                    } else {
                                        location.reload();
                                    }
                                }, 1500);
                            } else {
                                updateAlert(data.info);
                            }
                        });
                    }
                } else {
                    updateAlert(data.info);
                }
            }
        });

        return false;
    });
</script>
{/block}